<template>
	<view class="card">
		<block v-for="(item, index) in card" :key="index">
			<view :data-index="index" :data-item="item" @click="openCard"
				:class="'project item' + index + ' ' + (item.status ? 'flip' : '')">
<!-- 				<view class="front">
					<image :src="`${$BASE_URL_YIYUAN}/yiyuan/card.png`" mode="aspectFit"></image>
				</view>
				<view class="back">
					<image :src="item.img" mode="aspectFit"></image>
				</view> -->
					<image class="front" :src="`${$BASE_URL_YIYUAN}/yiyuan/card.png`" mode="aspectFit"></image>
					<image class="back" :src="item.image" mode="aspectFit"></image>
			</view>
		</block>
	</view>
</template>

<script>
	function runAsync(time) {
		return new Promise(function(resolve, reject) {
			const timer = setTimeout(function() {
				resolve();
				clearTimeout(timer);
			}, time);
		});
	}

	export default {
		data() {
			return {
				$BASE_URL_YIYUAN: this.$BASE_URL_YIYUAN
			};
		},

		components: {},
		props: {
			// 九宫格卡片
			card: {
				type: Array,
				default: new Array()
			}
		},
		mounted() {},
		methods: {
			// 点击打开单个卡片，开奖
			openCard(event) {
				const {
					item,
					index
				} = event.currentTarget.dataset; // 触发父组件方法

				this.$emit('open', {
					detail: {
						item,
						index
					}
				});
			}
		}
	};
</script>
<style lang="scss">
	.card {
		position: relative;
		margin: 0 auto;
		width: 560upx;
		height: 560upx;
	}

	.card .project {
		position: absolute;
		float: left;
		width: 166upx;
		height: 166upx;
		display: -ms-flexbox;
		display: flex;
		-ms-flex-pack: center;
		justify-content: center;
		-ms-flex-align: center;
		align-items: center;
	}

	.card .project image {
		width: 166upx;
		height: 166upx;
		box-shadow: 0 0 10upx rgba(0, 0, 0, 0.15);
		border-radius: 20upx;
	}

	.card .project .back,
	.card .project .front {
		-webkit-backface-visibility: hidden;
		backface-visibility: hidden;
		transform:rotateY(360deg);
		transition: all 1s;
		position: absolute;
		width: 100%;
		height: 100%;
		background-color: #FCC72B;
		border-radius: 20upx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.card .project .front {
		transform: rotateY(0)
	}

	.card .project .back {
		transform: rotateY(180deg)
	}

	.card .project.flip .back {
		transform: rotateY(0)
	}

	.card .project.flip .front {
		transform: rotateY(180deg)
	}

	.card .item0 {
		top: 0;
		left: 0
	}

	.card .item1 {
		top: 0;
		left: 200upx
	}

	.card .item2 {
		top: 0;
		left: 400upx
	}

	.card .item3 {
		top: 200upx;
		left: 0
	}

	.card .item4 {
		top: 200upx;
		left: 200upx
	}

	.card .item5 {
		top: 200upx;
		left: 400upx
	}

	.card .item6 {
		top: 400upx;
		left: 0
	}

	.card .item7 {
		top: 400upx;
		left: 200upx
	}

	.card .item8 {
		top: 400upx;
		left: 400upx
	}
</style>
